<?php
/*

*/
$path = dirname(__FILE__);
require_once("{$path}/class/BCGFontFile.php");
require_once("{$path}/class/BCGColor.php");
require_once("{$path}/class/BCGDrawing.php");
require_once "{$path}/class/BCGcode39.barcode.php";
require_once "{$path}/class/BCGcode93.barcode.php";
require_once("{$path}/class/BCGcode128.barcode.php");

class Silk_Zgb_BrController extends Mage_Core_Controller_Front_Action{
    public function renderAction()
    {
    	$path = dirname(__FILE__);
        $param = $this->getRequest()->getParam('code','ABC123456789');
        $text = $this->getRequest()->getParam('text');
        //$barcode = new BCGcode93();

        //QRcode::png($sku);

        // The arguments are R, G, and B for color.
		$colorFront = new BCGColor(0, 0, 0);
		$colorBack = new BCGColor(255, 255, 255);

		$font = new BCGFontFile("{$path}/font/ArialRDBD.ttf", 15);

		$code = new BCGcode128(); // Or another class name from the manual
		$code->setScale(2); // Resolution
		if($text)
		{
			$code->setThickness(20); // Thickness
		}
		else
		{
			$code->setThickness(30); // Thickness
		}
		
		$code->setForegroundColor($colorFont); // Color of bars
		$code->setBackgroundColor($colorBack); // Color of spaces
		if($text)
		{
			$code->setFont($font); // Font (or 0)
		}
		else
		{
			$code->setFont(0); // Font (or 0)
		}
		
		$code->parse($param); // Text

		$drawing = new BCGDrawing('', $colorBack);
		$drawing->setBarcode($code);
		$drawing->draw();

		$this->getResponse()->setHeader('Content-type', 'image/png');
		$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
    }
}